﻿@using DynamicLinqWebDocs.Models
@model DynamicLinqWebDocs.ViewModels.Class

@{
    string entityName;
    
    if (Model.IsInterface)
    {
        entityName = "Interface";
    }
    else
    {
        entityName = "Class";
    }

    ViewBag.Title = Model.Name + " " + entityName + " (" + Model.Namespace + ")";
    
    int[] s;
}

@Html.ActionLink("Back to Library", "Index", "Library", null, new { @class= "btn btn-xs btn-default" })

<h2>@Model.Name <small>@entityName</small></h2>

@Html.FormatMarkdown(Model.Description)

@Html.FormatMarkdown("**Namespace**: `{0}`", Model.Namespace)

@if (Model.Properties.Count > 0) {
    <h3>Properties</h3>       
    <table class="table">
        <thead>
            <tr>
                <th>Name</th>
                <th>Description</th>
                <th>Supported Frameworks</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var property in Model.Properties.OrderBy(x => x.Name).ThenBy(x => x.Frameworks))
            {
                var linkName = property.Name;
                Frameworks? framework = null;

                if (property.Frameworks != Frameworks.All)
                {
                    framework = Enum.GetValues(typeof(Frameworks)).Cast<Frameworks>().Reverse().Where(x => property.Frameworks.HasFlag(x)).FirstOrDefault();
                }

                <tr>
                    <td>@Html.ActionLink(linkName, "Property", "Library", new { className = Model.Name, propertyName = property.Name.Replace('<', '(').Replace('>', ')'), framework = framework }, null)</td>
                    <td>@Html.FormatMarkdown(property.Description)</td>
                    <td>@Helpers.GetEnumDescription(property.Frameworks)</td>
                </tr>
            }
        </tbody>
    </table>
}

@if (Model.Methods.Count > 0) { 
    <h3>Methods</h3>
    <table class="table">
        <thead>
            <tr>
                <th>Name</th>
                <th>Description</th>
                <th>Supported Frameworks</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var methodGroup in Model.Methods.OrderBy(x => x.Name).GroupBy(x => new { x.Name, x.Frameworks }))
            {
                int methodCount = 0;

                foreach (var method in methodGroup)
                {
                    var linkName = method.Name + "(" + String.Join(", ", method.Arguments.Select(x => x.Type)) + ")";
                    Frameworks? framework = null;

                    if (method.Frameworks != Frameworks.All)
                    {
                        framework = Enum.GetValues(typeof(Frameworks)).Cast<Frameworks>().Reverse().Where(x => method.Frameworks.HasFlag(x)).FirstOrDefault();
                    }
            
                    <tr>
                        <td>@Html.ActionLink(linkName, "Method", "Library", new { className = Model.Name, methodName = method.Name.Replace('<', '(').Replace('>', ')'), framework = framework, o = methodCount > 0 ? (int?)methodCount : null }, null)</td>
                        <td>@Html.FormatMarkdown(method.Description)</td>
                        <td>@Helpers.GetEnumDescription(method.Frameworks)</td>
                    </tr>
            
                    methodCount++;
                }
            }
        </tbody>
    </table>
}

@Html.DisplayFor(x => x.Remarks, "Remarks")